//
//  ProductDetailView.m
//  Peso Guide
//
//  Created by macbook on 2025/6/10.
//

#import "ProductDetailView.h"

@interface ProductDetailView ()

@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *priceLabel;

@property (nonatomic, strong) UILabel *downTitle1;
@property (nonatomic, strong) UILabel *downTitle2;
@property (nonatomic, strong) UILabel *downContent1;
@property (nonatomic, strong) UILabel *downContent2;

@property (nonatomic, strong) UIImageView *rightImg;

@end

@implementation ProductDetailView

- (id)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        
        self.backgroundColor = ColorHex(@"#1A7A35");
        
        _titleLabel = [PesoKit createLabelWithFrame:CGRectMake(22, 12, 200, 20) backGroundColor:[UIColor clearColor] text:@"" textColor:ColorHex(@"#FFFFFF") font:FONT(FontWeightStyleRegular, 14)];
        [self addSubview:_titleLabel];
        
        _priceLabel = [PesoKit createLabelWithFrame:CGRectMake(22, _titleLabel.bottom, 200, 42) backGroundColor:[UIColor clearColor] text:@"" textColor:ColorHex(@"#FFFFFF") font:FONT(FontWeightStyleMedium, 30)];
        [self addSubview:_priceLabel];
        
        _downTitle1 = [PesoKit createLabelWithFrame:CGRectMake(22, _priceLabel.bottom+9, 200, 20) backGroundColor:[UIColor clearColor] text:@"" textColor:ColorHex(@"#FFFFFF") font:FONT(FontWeightStyleRegular, 14)];
        [self addSubview:_downTitle1];
        
        _downContent1 = [PesoKit createLabelWithFrame:CGRectMake(22, _downTitle1.bottom, 200, 20) backGroundColor:[UIColor clearColor] text:@"" textColor:ColorHex(@"#FFFFFF") font:FONT(FontWeightStyleRegular, 14)];
        [self addSubview:_downContent1];
        
        _downTitle2 = [PesoKit createLabelWithFrame:CGRectMake(_downTitle1.right+20, _priceLabel.bottom+9, 200, 20) backGroundColor:[UIColor clearColor] text:@"" textColor:ColorHex(@"#FFFFFF") font:FONT(FontWeightStyleRegular, 14)];
        [self addSubview:_downTitle2];
        
        _downContent2 = [PesoKit createLabelWithFrame:CGRectMake(_downTitle1.right+20, _downTitle2.bottom, 200, 20) backGroundColor:[UIColor clearColor] text:@"" textColor:ColorHex(@"#FFFFFF") font:FONT(FontWeightStyleRegular, 14)];
        [self addSubview:_downContent2];
        
        _rightImg = [PesoKit createImageViewWithFrame:CGRectMake(KScreenWidth-14-150, 0, 150, 150) imageNamed:@""];
        _rightImg.backgroundColor = [UIColor clearColor];
        [self addSubview:_rightImg];
    }
    return self;
}

- (void)setDataDic:(NSDictionary *)dataDic {
    _dataDic = dataDic;
    NSString *manual = [NSString stringWithFormat:@"%@",[dataDic safeObjectForKey:@"manual"]];
    NSDictionary *traditionally = [NSDictionary safeDictionaryWithDictionary:[dataDic safeObjectForKey:@"traditionally"]];
    NSString *returning = [NSString stringWithFormat:@"%@",[dataDic safeObjectForKey:@"returning"]];
    NSDictionary *software = [NSDictionary safeDictionaryWithDictionary:[traditionally safeObjectForKey:@"software"]];
    NSDictionary *you = [NSDictionary safeDictionaryWithDictionary:[traditionally safeObjectForKey:@"you"]];
    NSString *accidental = [NSString stringWithFormat:@"%@",[software safeObjectForKey:@"accidental"]];
    NSString *april = [NSString stringWithFormat:@"%@",[software safeObjectForKey:@"april"]];
    NSString *accidental2 = [NSString stringWithFormat:@"%@",[you safeObjectForKey:@"accidental"]];
    NSString *april2 = [NSString stringWithFormat:@"%@",[you safeObjectForKey:@"april"]];
    NSString *compilation = [NSString stringWithFormat:@"%@",[dataDic safeObjectForKey:@"compilation"]];
    NSString *raised = [NSString stringWithFormat:@"%@",[dataDic safeObjectForKey:@"raised"]];

    _titleLabel.text = manual;
    _priceLabel.text = [NSString stringWithFormat:@"%@ %@",compilation,returning];
    _downTitle1.text = accidental;
    _downTitle2.text = accidental2;
    _downContent1.text = april;
    _downContent2.text = april2;
    [_rightImg sd_setImageWithURL:[NSURL URLWithString:raised]];
    
    CGSize downTitleSize = [AppTools sizeWithText:_downTitle1.text font:FONT(FontWeightStyleRegular, 14) maxSize:CGSizeMake(200, 20)];
    _downTitle1.frame = CGRectMake(22, _priceLabel.bottom+9, ceil(downTitleSize.width)+5, 20);
    _downContent1.frame = CGRectMake(22, _downTitle1.bottom, ceil(downTitleSize.width)+5, 20);
    _downTitle2.frame = CGRectMake(_downTitle1.right+20, _priceLabel.bottom+9, 200, 20);
    _downContent2.frame = CGRectMake(_downTitle1.right+20, _downTitle1.bottom, 200, 20);
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
